package com.kaishengit.service;

import org.apache.commons.mail.Email;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.kaishengit.pojo.User;

@Service
@Transactional
public class EmailService {

	
	public void sendEmail(User user, String emailaddress, String title, String content) {
		
		
			Email email = new SimpleEmail();
			email.setHostName("smtp.qq.com");
			System.out.println(user.getEmail());
			System.out.println(user.getEmailpwd());
			email.setAuthentication(user.getEmail(), user.getEmailpwd());
			email.setCharset("UTF-8");
			email.setTLS(true);
			try {
				email.setFrom(user.getEmail());
				email.setSubject(title);
				email.setMsg(content);
				email.addTo(emailaddress);
				email.send();
			} catch (EmailException e) {
				e.printStackTrace();
			}
			
		
	
		
	}
	

}
